var request = require('request');

var url_8080_pattern = "http://localhost:8080/?time={time}";
var url_8081 = "http://localhost:8081/";

function reqOnce() {

	var url_8080 = url_8080_pattern.replace('{time}', 1);
	var start = new Date().getTime();


	request(url_8080, function(err, res, body) {
		var cost = new Date().getTime() - start;
		console.log('http 8080 reqOnce cost=%s', cost);
	});

	request(url_8081, function(err, res, body) {
		var cost = new Date().getTime() - start;
		console.log('http 8081 reqOnce cost=%s', cost);
	});
}


function runMany(times) {
	var url_8080 = url_8080_pattern.replace('{time}', times);
	var count1 = 0;
	var start1 = new Date().getTime();
	function foo1() {
		request(url_8080, function(err, res, body) {
			var cost1 = new Date().getTime() - start1;
			console.log('http 8080 runMany cost=%s,times=%s', cost1, times);
		});
	}
	foo1(); // 100times ~ 2500ms

	// var count2 = 0;
	// var start2 = new Date().getTime();
	// function foo2() {
	// 	for (var i = 0; i < times; i++) {
	// 		request(url_8081, function(err, res, body) {
	// 			count2++;

	// 			if (count2 === times) {
	// 				var cost2 = new Date().getTime() - start2;
	// 				console.log('http 8081 runMany cost=%s,times=%s', cost2, times);
	// 			}
	// 		});
	// 	}
	// }
	// foo2(); // 100times ~ 450ms

}

// reqOnce();

runMany(1000);